#!/usr/bin/env bash

# maxwell.sh

# Copyright (C) 2010 Scott C. MacCallum
# scottmaccal@gmail.com

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#       |                                  80 Columns                                    |

faridayix_build=$HOME/faridayix-build
block_cursor='\e[?6c'
white_foreground='\e[40m\033[1m'
green_foreground='\e[32m\033[1m'
default_foreground='\033[0m'

#******************
# Introduce Maxwell
#******************
echo -e $block_cursor
echo -e $white_foreground
clear
printf "Hello $USER, my name is Maxwell."
printf "\n\n"
sleep 4

clear
printf "I will help you build the Faridayix operating system."
printf "\n\n"
sleep 4

#*****************************
# Make File System Directories
#*****************************
# Make faridayix-build directory
clear
printf "I will start by making the following file system directories:"
printf "\n\n"
mkdir --parents $HOME/faridayix-build
printf "\n"
sleep 4

# Make binary directory
printf "binary"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/bin
echo -e $default_foreground
echo -e $white_foreground
sleep 4

# Make boot directory
printf "boot"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/boot
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make defaults directory
printf "defaults"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/defaults
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make devices directory
printf "devices"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/dev
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4 

# Make etcetera directory
printf "etcetera"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/etc
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make etcetera, defaults directory
printf "etcetera, defaults"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/etc/defaults
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make ecetera, mail directory
printf "ecetera, mail"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/etc/mail
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make periodic directory
printf "periodic"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/etc/periodic
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make ectera, point-to-point protocol directory
printf "ecetera, point-to-point protocol"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/etc/ppp
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make mount direcory
printf "mount"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/mnt
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make processes directory
printf "processes"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/proc
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make rescue directory
printf "rescue"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/rescue
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make root directory
printf "root"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/root
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make source directory
printf "source"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/src
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make system binary directory
printf "system binary"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/sbin
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

# Make temporary directory
printf "temporary"
printf "\n\n"
echo -e $green_foreground
mkdir --verbose $faridayix_build/tmp
echo -e $default_foreground
echo -e $white_foreground
printf "\n"
sleep 4

#*******************************
# Get Software From the Internet
#*******************************

# Search of these programs first. If that are not there fecth.

# Get the Burrows-Wheeler transform zip two binary program for the i386

# Get the GNUs Not UNIX zip binary program for the i386

# Get the GNUs Not UNIX tape archiver binary program for the i386

# Get the latest stable release of the Burrows-Wheeler transform zip two program
clear
printf "I will now download a compressed archive of the latest stable release of the Burrows-Wheeler transform zip two program."
printf "\n\n"
echo -e $green_foreground
pushd $faridayix_build/src
printf "\n\n"
curl --location --remote-name http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
echo -e $default_foreground
echo -e $white_foreground
printf "\n\n"
sleep 4

# Get the latest stable release of the GNUs Not UNIX zip program
clear
printf "I will now download a compressed archive of the latest stable release of the GNUs Not UNIX zip program."
printf "\n\n"
echo -e $green_foreground
pushd $faridayix_build/src
printf "\n\n"
curl --location --remote-name ftp://ftp.gnu.org/gnu/gcc/gcc-4.4.2/gcc-core-4.4.2.tar.bz2
echo -e $default_foreground
echo -e $white_foreground
printf "\n\n"
sleep 4

# Get the latest stable release of the GNUs Not UNIX tape archiver program
clear
printf "I will now download a compressed archive of the latest stable release of the tape archiver program."
printf "\n\n"
echo -e $green_foreground
pushd $faridayix_build/src
printf "\n\n"
curl --location --remote-name ftp://ftp.gnu.org/gnu/gcc/gcc-4.4.2/gcc-core-4.4.2.tar.bz2
echo -e $default_foreground
echo -e $white_foreground
printf "\n\n"
sleep 4

# Get the latest stable release of the Burrows-Wheeler transform zip two program
clear
printf "I will now download a compressed archive of the latest stable release of the core GNUs Not UNIX Compiler Collection."
printf "\n\n"
echo -e $green_foreground
pushd $faridayix_build/src
printf "\n\n"
curl --location --remote-name http://www.bzip.org/1.0.5/bzip2-1.0.5.tar.gz
echo -e $default_foreground
echo -e $white_foreground
printf "\n\n"
sleep 4

# Get the latest stable release of the core GNUs Not UNIX compiler collection
clear
printf "I will now download a compressed archive of the latest stable release of the core GNUs Not UNIX Compiler Collection."
printf "\n\n"
echo -e $green_foreground
pushd $faridayix_build/src
printf "\n\n"
curl --location --remote-name ftp://ftp.gnu.org/gnu/gcc/gcc-4.4.2/gcc-core-4.4.2.tar.bz2
echo -e $default_foreground
echo -e $white_foreground
printf "\n\n"
sleep 4

# Get the latest stable release of the Linux kernel version two point four
clear
printf "I will now download a compressed archive of the latest stable release of the Linux Kernel Version 2.4."
printf "\n\n"
echo -e $green_foreground
printf "\n\n"
curl --location --remote-name http://www.kernel.org/pub/linux/kernel/v2.4/linux/
echo -e $default_foreground
echo -e $white_foreground
printf "\n\n"
sleep 4

# Get the latest stable release of the Linux kernel version two point six
clear
printf "I will now download a compressed archive of the latest stable release of the Linux Kernel Version 2.4."
printf "\n\n"
echo -e $green_foreground
printf "\n\n"
curl --location --remote-name http://www.kernel.org/pub/linux/kernel/v2.6/linux/
echo -e $default_foreground
echo -e $white_foreground
printf "\n\n"
sleep 4

# Get the latest stable release of the Bourne again shell
curl --verbose --location --remote-name ftp://ftp.gnu.org/gnu/bash/bash-4.1.tar.gz
curl --verbose --location --remote-name ftp://ftp.gnu.org/gnu/emacs/emacs-23.1.tar.gz
curl --verbose --location --remote-name http://www.python.org/ftp/python/3.11/Python-3.1.1.tar.bz2
curl --verbose --location --remote-name http://www.mercurial.selenic.com/release/mercurial-1.4.2.tar.gz

printf "I will now uncompress and extract the archive of the latest stable release of the core GNUs Not UNIX Compiler Collection to the build directory."
printf "\n\n"
tar --verbose --bzip2 --extract --file gcc-core-4.4.2.tar.bz2
printf "\n\n"

tar --verbose --bzip2 --extract --file linux-2.6.32.3.tar.bz2
tar --verbose --gunzip --extract --file bash-4.1.tar.gz
tar --verbose --gunzip --extract --file emacs-23.1.tar.gz
tar --verbose --bzip2 --extract --file Python-3.1.1.tar.bz2
tar --verbose --bzip2 --extract --file mercurial-1.4.2.tar.gz